<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <div data-index="1"></div>
    <script>
        var div = document.querySelector('div');
        console.log(div.getAttribute('data-index'));
        div.setAttribute('data-ko', '2');
        // dataset获取data开头的H5属性
        console.log(div.dataset.index);
    </script>
</body>

</html>